//
//  MTNewMineView.m
//  met
//
//  Created by 李晓俊 on 2019/6/5.
//  Copyright © 2019 李晓俊. All rights reserved.
//

#import "MTNewMineView.h"

@implementation MTNewMineView
{
    
    CGRect myframe;
    
}
- (MTNewMineView *)initWithFrame:(CGRect)frame

{
    self = [super initWithFrame:frame];
    if (self) {
        NSArray *nibs=[[NSBundle mainBundle]loadNibNamed:@"MTNewMineView" owner:nil options:nil];
        self=[nibs objectAtIndex:0];
        myframe = frame;
    
        self.bgView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick)];
        [self.bgView addGestureRecognizer:tap];
    }
    return self;
}
-(void)drawRect:(CGRect)rect

{
    self.frame=myframe;//关键点在这里
}

- (void)tapClick {
    if (self.selectChoose) {
        self.selectChoose(self.model);
    }
}
- (void)setInfoDic:(NSDictionary *)infoDic {
    _infoDic = infoDic;
    self.question.text = [NSString stringWithFormat:@"%@",[infoDic objectForKey:@"storyName"]];

    NSString *praiseNum = [NSString stringWithFormat:@"%@",[infoDic objectForKey:@"praiseNum"]];
    if ([praiseNum isEqualToString:@""]||[praiseNum isEqualToString:@"<null>"]) {
        praiseNum = @"0";
    }else {
        praiseNum = [NSString stringWithFormat:@"%@",[infoDic objectForKey:@"praiseNum"]];
    }
    self.mainImage.image = [UIImage imageNamed:@"背景图"];
     [self.headImage sd_setImageWithURL:[NSURL URLWithString:KUSER.portraitMap] placeholderImage:[UIImage imageNamed:@"椭圆 1 拷贝 7"] ];
    self.name.text = [NSString stringWithFormat:@"%@",KUSER.nickName];
    self.likeCount.text = praiseNum;
}
- (void)setModel:(UserStoryYinJiModel *)model {
    _model = model;
    self.question.text = [NSString stringWithFormat:@"%@",model.objectTitle];
    NSString *praiseNum = [NSString stringWithFormat:@"%@",model.praiseNum];
    if ([praiseNum isEqualToString:@""]||[praiseNum isEqualToString:@"<null>"]) {
        praiseNum = @"0";
    }else {
        praiseNum = [NSString stringWithFormat:@"%@",model.praiseNum];
    }
//    self.mainImage.image = [UIImage imageNamed:@"背景图"];
    [self.mainImage sd_setImageWithURL:[NSURL URLWithString:model.cover] placeholderImage:[UIImage imageNamed:@"漂流卡-1"]];
    self.mainImage.contentMode = 0;
    self.headImage.contentMode = 0;
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:model.portraitMap] placeholderImage:[UIImage imageNamed:@"椭圆 1 拷贝 7"] ];
    self.name.text = [NSString stringWithFormat:@"%@",model.nickName];
    self.likeCount.text = praiseNum;
    if ([[NSString stringWithFormat:@"%@",model.objectType]isEqualToString:@"1"]) {
//印记
        NSUserDefaults *dataUser = [NSUserDefaults standardUserDefaults];
        [dataUser setObject:@"1" forKey:@"yinji"];
        [dataUser synchronize];
    }else {
        NSUserDefaults *dataUser = [NSUserDefaults standardUserDefaults];
        [dataUser setObject:@"1" forKey:@"fabu"];
        [dataUser synchronize];
    }
}
@end
